# -*- coding: utf-8 -*-
# @Author   : Claus
# @Time     : 2020/6/21 19:36
# @FileName : Phone.py
from time import sleep

info_list = []


def index():
    print("-------------------------------------")
    print("1: 添加联系人")
    print("2: 查看联系人")
    print("3: 删除联系人")
    print("0: 退出程序")
    print("-------------------------------------")


def add():
    while True:
        print("请输入姓名:")
        name = input()
        print("请输入电话号码:")
        telephone = input()
        item = {}
        item["姓名"] = name
        item["电话"] = telephone
        info_list.append(item)
        print(f"[{name} -- {telephone}] --> 添加成功")
        print("-------------------------------------")
        print("1: 继续添加联系人")
        print("2: 退出")
        print("-------------------------------------")
        u = input()
        if u == "1":
            continue
        elif u == "2":
            return
        else:
            print("参数有误, 请重新输入")


def look():
    while True:
        if len(info_list) == 0:
            print("无任何联系人, 请先添加")
            sleep(1)
            return
        print("姓名\t\t\t", "号码\t\t\t", sep="\t\t\t")
        for d in info_list:
            print(f'{d["姓名"].ljust(14)}', f'{d["电话"].ljust(14)}', sep="\t\t\t")
            print("-------------------------------------")
            print("1: 再次查看联系人")
            print("2: 退出")
            print("-------------------------------------")
            u = input()
            if u == "1":
                continue
            elif u == "2":
                break
            else:
                print("参数有误, 请重新输入")


def delete():
    while True:
        if len(info_list) == 0:
            print("无任何联系人, 请先添加")
            sleep(1)
            return
        n = 1
        for d in info_list:
            print(f"{n}: ", d["姓名"], sep="\t\t\t")
            n += 1
        print("请选择你要删除的联系人")
        user_select = input()
        u = int(user_select)
        name = info_list[u - 1]["姓名"]
        del info_list[u - 1]
        if len(info_list) == 0:
            print("联系人以为空")
            sleep(1)
            return
        print(f"{name} --> 删除成功")
        print("-------------------------------------")
        print("1: 继续删除")
        print("2: 退出")
        print("-------------------------------------")
        u = input()
        if u == "1":
            continue
        elif u == "2":
            return
        else:
            print("参数有误, 请重新输入")
            sleep(1)


def main():
    while True:
        index()
        print("请输入选项: ")
        user_select = input()
        if user_select == "0":
            print("期待下次与您见面, bye")
            sleep(1)
            return
        if user_select == "1":
            add()
            sleep(1)
        elif user_select == "2":
            look()
            sleep(1)
        elif user_select == "3":
            delete()
            sleep(1)
        else:
            print("参数有误, 请重新输入")
            sleep(1)


if __name__ == '__main__':
    main()
